package cn.com.joycode.nimble.core.utils;

import cn.hutool.core.util.StrUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class NbHexUtil {

    private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    public static String encodeSplitHexStr(byte[] data) {
        StringBuilder sb = new StringBuilder();
        final int len = data.length;
        // two characters from the hex value.
        for (int i = 0, j = 0; i < len; i++) {
            char high = DIGITS_UPPER[(0xF0 & data[i]) >>> 4];
            char low = DIGITS_UPPER[0x0F & data[i]];
            sb.append(high);
            sb.append(low);
            sb.append(StrUtil.SPACE);
        }
        return StrUtil.trimEnd(sb.toString());
    }
}
